<template>
	<view class="whole">
		<u-toast ref="uToast" />
		<view class="input">
			<view>
				<input class="input_top" type="text" v-model="value" placeholder="请描述你遇到的问题" placeholder-style="font-size:28rpx;color: #BBBBBE ;" disabled=false/>
				<!-- <text class="input_top" >请描述你遇到的问题</text> -->
			</view>
			<view style="height: 2rpx;background-color: #262934 ;"></view>
			<view>
				<input class="input_center" type="textarea"  v-model="content" placeholder="描述问题已便我们提供更好的帮助" style="word-break:break-all;font-size: 28rpx;" placeholder-style="font-size:28rpx"/>
			</view>
		</view>
		<view class="upload">
			<view style="padding: 25rpx 20rpx;font-size: 32rpx;color: #BBBBBE ;">
				<text >上传截图  ({{Upimg.length > 3 ? 3 : Upimg.length}}/3)</text>
			</view>
			<!-- <img src="/static/shopping_add.png" alt="" style="width: 80rpx;height: 80rpx;" class="upload_img" @click='upload_img'> -->
			<view class="upload_upload">
				<view class="" style="display: flex;">
			   	<view v-for="(item,index) in Upimg"  v-if="Upimg.length!=0" style="display: flex;justify-content: space-between;position: relative;" >
						<!-- <image src="/static/shopping_add.png" 
							 @click="remove(index)"
							style="position: absolute;top: 0%;right: 30rpx; width: 30rpx;height: 30rpx;z-index: 2;">
							</image> -->
			   			<image :src="item" mode="" style="width: 170rpx;height: 170rpx;margin: 0rpx 30rpx;"  @click="remove(index)"></image>
			   	</view>
					</view>
					<view class="">
						<image src="/static/shopping_add.png"  class="upload_img" @click='uploadimg(1)' v-if="Upimg.length!=3">
					</view>
				<!-- <u-upload :action="action" :file-list="fileList" max-count="3" :before-upload="beforeUpload" name="file" ></u-upload> -->
			</view>
		</view>
		<view style="margin-top: 30rpx;">
			<view class="bootm">
				<view class="set_name" style="margin-right: 35rpx;">联系人</view>
				<input class="modal-input" type="text" v-model="contact" placeholder="填写联系称呼" placeholder-style="font-size:32rpx" style="font-size: 32rpx;"  />
			</view>
			<view style="height: 2rpx;background-color: #262934 ;"></view>
			<view class="bootm">
				<view class="set_name">联系电话</view>
				<input class="modal-input" type="text" v-model="contact_phone" placeholder="填写联系称呼"  placeholder-style="font-size:32rpx" style="font-size: 32rpx;" />
			</view>
			
			<template>
				<view class="button" @click="Submit()">
					确定
				</view>
			</template>
		</view>
		
		<u-select v-model="show" :list="list" @confirm='confirm'></u-select>
		
	</view>
</template>

<script>
import api from "../../api/api";
import { uploadImage } from "../../utils/upLoad.js";
export default {
  data() {
    return {
      show: false,
      list: [
        {
          value: "1",
          label: "删除",
        },
      ],
      value: "",
      content: "",
      images: [],
      contact: "",
      contact_phone: "",
      fileList: [],
      lengths: 0,
      action: "https://up-z2.qiniup.com/",
      Upimg: [],
      listindex: 0,
    };
  },
  methods: {
    confirm() {
      this.Upimg.splice(this.listindex, 1);
    },
    remove(index) {
      this.show = true;
      this.listindex = index;
      return;
      this.Upimg.splice(index, 1);
    },
    async uploadimg() {
      let res = await uploadImage();
      console.log(res, "res");
      // this.Upimg.push(res[0]);
      if (res.length > 3) {
        this.Upimg = this.Upimg.concat(res.slice(0, 3));
      } else {
        this.Upimg = this.Upimg.concat(res);
      }
      if (this.Upimg.length > 3) {
        this.Upimg = this.Upimg.splice(0, 3);
      }
    },
    beforeUpload(index, list) {
      this.lengths = index + 1;
      console.log(index, list);
      this.images.push(list[index].url);
      console.log(this.images);
    },
    async Submit() {
      if (this.content == "") {
        this.$refs.uToast.show({
          title: "请输入内容",
          type: "error",
        });
        return;
      }
      if (this.contact == "") {
        this.$refs.uToast.show({
          title: "请输入联系人",
          type: "error",
        });
        return;
      }
      if(this.contact_phone==''){
      	this.$refs.uToast.show({
      		title: '请输入手机号',
      		type: 'error',
      	})
      	return;
      }
      if(!(/^1[3456789]\d{9}$/.test(this.contact_phone))){
      	 this.$refs.uToast.show({
      	 	title: '请填写正确手机号',
      		type: 'error',
      	 })
      	 return;
      }
      let res = await api.feedback({
        query: {
          content: this.content,
          images: this.Upimg,
          contact: this.contact,
          contact_phone: this.contact_phone,
        },
        method: "post",
      });
      if (res.code == 0) {
        this.$refs.uToast.show({
          title: "反馈成功",
          type: "success",
        });
        setTimeout(() => {
          uni.navigateBack({
            delta: 1, //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
          });
        }, 500);
      } else {
        this.$refs.uToast.show({
          title: res.msg,
          type: "error",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.whole {
  background-color: $bg-color1;
  min-height: 100vh;
  .input_top {
    color: #bbbbbe;
    height: 100rpx;
    margin-left: 30rpx;
  }
  .input_center {
    color: #ffffff;
    // height: 260rpx;
    padding: 30rpx 0 100rpx;
    margin-left: 30rpx;
    word-break: break-all;
  }
  .input {
    position: relative;
    top: 30rpx;
    background-color: $bg-color3;
    color: #ffffff;
  }
  .upload_upload {
    display: flex;
    align-content: flex-start;
  }
  .upload {
    margin-top: 50rpx;
    background-color: $bg-color3;
    height: 300rpx;
    padding-left: 20rpx;
  }
  .bootm {
    background-color: $bg-color3;
    display: flex;
    align-items: center;
    padding: 10rpx;
    .set_name {
      padding: 20rpx 30rpx;
      color: #bbbbbe;
      font-size: 32rpx;
    }
    .modal-input {
      color: #ffffff;
    }
  }
  .button {
    position: relative;
    top: 100rpx;
    margin: 30rpx;
    height: 90rpx;
    color: $text-color4;
    background: $button;background-repeat: no-repeat;background-size: 100%;
    text-align: center;
    line-height: 90rpx;
    font-size: 32rpx;
    border-radius: 16rpx;
  }
  .upload_img {
    margin-left: 20rpx;
    // margin-top: 10rpx;
    width: 170rpx;
    height: 170rpx;
    // padding: 45rpx;
    background-color: #999999;
  }
}
</style>
